package LearnAlgorithm.f_字符串;

public class j判断回文串 {
	public static void main(String[] args) {
		String string = "abbddbba";
//		System.out.println(isPalindromeApi(string));
		System.out.println(isPalindromeByMy(string));
		palindromeNumber();
	}
	
	public static boolean isPalindromeApi(String string) {
		if (string == null || string.length() == 0) {
			return true;
		}
		return string.equals(new StringBuilder(string).reverse().toString());
	}
	
	public static boolean isPalindromeByMy(String string) {
		if (string == null || string.length() == 0) {
			return true;
		}
		char[] charArray = new char[string.length()];
		for (int i = 0; i < charArray.length; i++) {
			charArray[i] = string.charAt(string.length() - 1 - i);
		}
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i] != string.charAt(i)) {
				return false;
			}
		}
		return true;
	}
	
	/**
	 * 附加题：求4位数的所有回文数
	 * 从小到大输出
	 */
	public static void palindromeNumber() {
		for (int i = 1; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				System.out.println(i * 1000 + j * 100 + j * 10 + i);
			}
		}
	}
}
